package com.farmer.lazycoder.util;

import com.farmer.lazycoder.vo.ConnectionInfo;

import java.sql.Connection;
import java.sql.DriverManager;

/**
 * @auther yz
 * @date 2019/3/28
 **/
public class DBUtil {
    public static String driver = "com.mysql.cj.jdbc.Driver";
    public static Connection getConnection(ConnectionInfo connectionInfo) {
        Connection connection = null;
        try {
            Class.forName(driver);
            connection = DriverManager.getConnection("jdbc:mysql://"+connectionInfo.getIp()+":"+connectionInfo.getPort()+"/"+connectionInfo.getDbname()+"?serverTimezone=UTC&characterEncoding=utf8&useUnicode=true&useSSL=false&nullNamePatternMatchesAll=true",connectionInfo.getUserName(),connectionInfo.getPassword());
        } catch(Exception e) {
            e.printStackTrace();
        }
        return connection;
    }
}
